﻿@using System.Globalization;
@using EventbriteApi.Model;

@helper GetHtml(IEnumerable<Event> eventList, string title) {

	<link rel="stylesheet" href="@Href("~/Eventbrite/Content/Styles.css")" type="text/css"/>
	<script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js" type="text/javascript"></script>

	<div id="events_sec" sizcache="14" sizset="0">
	  <ul class="tabs">
		<li class="active">
		  <a href="#">@title</a>
		</li>
	  </ul>
	  <div class="clear_left"></div>
	  <div id="user_events" class="user_events_tab ">
	  @foreach (var eventItem in eventList) {
		<div class="event_row first_row">
		  <div class="start_date">
			<span class="day">@eventItem.StartDateUtc.ToString("ddd", CultureInfo.CurrentCulture)</span>
			<span class="date">@eventItem.StartDateUtc.ToString("MMM dd", CultureInfo.CurrentCulture)</span>
		  </div>
		  <div class="event">
			<a href="@eventItem.Url" target="_blank">@eventItem.Title</a>
			<span>@eventItem.StartDateUtc.ToString("f", CultureInfo.CurrentCulture) GMT</span>
		  </div>
		  <div class="calendar">
			<div class="add" id="calendar_add_@(eventItem.Id)"><a href="javascript: ToggleCalendar('@eventItem.Id');">Add to my calendar</a></div>
			<div class="options" id="calendar_options_@(eventItem.Id)" style="display:none;">
			  <div class="close" onclick="ToggleCalendar('@eventItem.Id')"></div>
			  <a class="wlive" href="javascript: AddToLiveCalendar('@eventItem.StartDateUtc.ToString("yyyyMMddTHHmmssZ")', '@eventItem.EndDateUtc.ToString("yyyyMMddTHHmmssZ")', '@(eventItem.Title ?? "")', '@(eventItem.Venue != null ? eventItem.Venue.ToString() : "")');">Windows Live Calendar</a>
			  <a class="google" href="javascript: AddToCalendar('google', '@eventItem.Id');">Google Calendar</a>
			  <a class="ical" href="javascript: AddToCalendar('ical', '@eventItem.Id');">iCal/Outlook Calendar</a>		
			</div>
		  </div>
		  <div class="clear_both">
		  </div>
		</div>
	  }
	  </div>
	</div>

	<script type="text/javascript">
		function ToggleCalendar(eid) {
			$('#calendar_add_' + eid).toggle();
			$('#calendar_options_' + eid).toggle();
		};

		function AddToCalendar(calendar, eid) {
			var url = 'http://www.eventbrite.com/calendar.ics?eid='+eid+'&calendar='+calendar;

			if(calendar=='outlook' || calendar=='ical')
				document.location.href = url;
			else
				window.open(url,'calendar','toolbar=yes, menubar=yes, location=yes, status=yes, scrollbars=yes, resizable=yes, width=800, height=600, left=0, top=0');
		};

		function AddToLiveCalendar(dtstart, dtend, title, location) {
			var url = 'http://calendar.live.com/calendar/calendar.aspx?rru=addevent&dtstart='+dtstart+'&dtend='+dtend+'&summary='+escape(title)+'&location='+escape(location);

			window.open(url,'calendar','toolbar=yes, menubar=yes, location=yes, status=yes, scrollbars=yes, resizable=yes, width=800, height=600, left=0, top=0');
		};
	</script>
}